package cn.tedu._05weibo.common.response;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

@Setter
@Getter
@AllArgsConstructor
@NoArgsConstructor
public class JsonResult {
    @ApiModelProperty(value = "状态码", example = "200")
    private Integer status;
    @ApiModelProperty(value = "消息", example = "操作成功")
    private String message;
    @ApiModelProperty(value = "数据", example = "{}")
    private Object data;

    public JsonResult(StatusCode statusCode) {
        this.status = statusCode.getState();
        this.message = statusCode.getMessage();
    }

    public JsonResult(StatusCode statusCode, Object data) {
        this.status = statusCode.getState();
        this.message = statusCode.getMessage();
        this.data = data;
    }

    /**
     * 操作成功封装成响应结果
     */
    public static JsonResult ok() {
        return new JsonResult(StatusCode.OPERATION_SUCCESS);
    }

    public static JsonResult ok(Object data) {
        return new JsonResult(StatusCode.OPERATION_SUCCESS, data);
    }

}
